from rest_framework import serializers
from recruit.models import Enterprise, Recruit
from .recruit_serializers import UserSerializer


# 热门企业，增加企业访问次数
class HotEnterpriseSerializer(serializers.ModelSerializer):

    class Meta:
        model = Enterprise
        fields = [
            'id',
            'name',
            'labels',
            'logo',
            'summary',
            'recruits'
        ]


# 企业详情，职位关联的企业，three
class EnterRecruitThree(serializers.ModelSerializer):
    recruits = serializers.StringRelatedField()

    class Meta:
        model = Enterprise
        fields = [
            'id',
            'name',
            'labels',
            'logo',
            'recruits',
            'summary'
        ]


# 企业详情，关联的多个职位，second
class EnterRecruitSecond(serializers.ModelSerializer):
    enterprise = 0

    class Meta:
        model = Recruit
        fields = '__all__'


# 企业详情，第一层
class EnterDetailSerializer(serializers.ModelSerializer):
    users = UserSerializer(many=True)
    recruits = EnterRecruitSecond

    class Meta:
        model = Enterprise
        fields = '__all__'


